home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 123 / cdrom123.iso / essenc / extens / wweb / Web Developer.xpi / chrome / webdeveloper.jar / content / webdeveloper / outline.js < prev    next >
Encoding:
JavaScript  |  2004-11-21  |  9.0 KB  |  197 lines

  1. // Ignores the click event
  2. function webdeveloper_ignoreClick(event)
  3. {
  4.     // If there is an event target and the click was not a right click
  5.     if(event.target && event.button != 2)
  6.     {
  7.         event.preventDefault();
  8.     }
  9. }
  10.  
  11. // Outlines all block level elements
  12. function webdeveloper_outlineBlockLevelElements(element, applyStyle)
  13. {
  14.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  15.  
  16.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_block_level_elements.css", "webdeveloper-outline-block-level-elements", applyStyle);
  17.  
  18.     // If the show outlined element names preference is set
  19.     if(preferencesService.prefHasUserValue("webdeveloper.outline.show.element.names") && preferencesService.getBoolPref("webdeveloper.outline.show.element.names"))
  20.     {
  21.         webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_block_level_elements_before.css", "webdeveloper-outline-block-level-elements-before", applyStyle);
  22.         webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-outline-block-level-elements-before-tooltips", "*:before");
  23.     }
  24. }
  25.  
  26. // Outlines the given element
  27. function webdeveloper_outlineCustomElements(element)
  28. {
  29.     webdeveloper_outlinedElements = new Array();
  30.  
  31.     // If the menu is checked
  32.     if(element.getAttribute("checked"))
  33.     {
  34.         window.openDialog("chrome://webdeveloper/content/dialogs/outline_elements.xul", "webdeveloper-outline-elements-dialog", "centerscreen,chrome,modal", webdeveloper_outlinedElements);
  35.  
  36.         // If the user clicked cancel in the dialog
  37.         if(webdeveloper_outlinedElements.length == 0)
  38.         {
  39.            element.removeAttribute("checked");
  40.         }
  41.     }
  42.  
  43.     webdeveloper_outlineElements(element, true);
  44. }
  45.  
  46. // Outlines all deprecated elements
  47. function webdeveloper_outlineDeprecatedElements(element, applyStyle)
  48. {
  49.     const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  50.  
  51.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_deprecated_elements.css", "webdeveloper-outline-deprecated-elements", applyStyle);
  52.  
  53.     // If the show outlined element names preference is set
  54.     if(preferencesService.prefHasUserValue("webdeveloper.outline.show.element.names") && preferencesService.getBoolPref("webdeveloper.outline.show.element.names"))
  55.     {
  56.         webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_deprecated_elements_before.css", "webdeveloper-outline-deprecated-elements-before", applyStyle);
  57.         webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-outline-deprecated-elements-before-tooltips", "*:before");
  58.     }
  59. }
  60.  
  61. // Outlines the given element
  62. function webdeveloper_outlineElements(element, applyStyle)
  63. {
  64.     // If the menu is checked
  65.     if(element.getAttribute("checked") && webdeveloper_outlinedElements.length > 0)
  66.     {
  67.         const content            = window.document.getElementById("content");
  68.         const mainTabBox         = content.mTabBox;
  69.         const documentList       = webdeveloper_getDocuments(content.browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  70.         const preferencesService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
  71.  
  72.         var headElementList     = null;
  73.         var outlineColor        = null;
  74.         var outlineElement      = null;
  75.         var outlineElementList  = null;
  76.         var outlineElementValue = null;
  77.         var pageDocument        = null;
  78.         var styleElement        = null;
  79.  
  80.         // Loop through the documents
  81.         for(var i = 0; i < documentList.length; i++)
  82.         {
  83.             pageDocument    = documentList[i];
  84.             headElementList = pageDocument.getElementsByTagName("head");
  85.             styleElement    = pageDocument.createElement("style");
  86.  
  87.             styleElement.setAttribute("id", "webdeveloper-outline-custom-elements");
  88.             styleElement.setAttribute("type", "text/css");
  89.  
  90.             // Loop through outline colors and elements
  91.             for(var j = 0; j <= 5; j++)
  92.             {
  93.                 outlineColor   = "webdeveloper.custom." + j + ".color";
  94.                 outlineElement = "webdeveloper.custom." + j + ".element";
  95.  
  96.                 // If the color and element are set and not blank
  97.                 if(preferencesService.prefHasUserValue(outlineColor) && preferencesService.prefHasUserValue(outlineElement) && preferencesService.getCharPref(outlineColor) != "" && preferencesService.getCharPref(outlineElement).trim() != "")
  98.                 {
  99.                     outlineElementList = preferencesService.getCharPref(outlineElement).trim().split(",");
  100.  
  101.                     // Loop through the elements
  102.                     for(var k = 0; k < outlineElementList.length; k++)
  103.                     {
  104.                         outlineElementValue = outlineElementList[k];
  105.                         styleElement.appendChild(pageDocument.createTextNode(outlineElementValue + " { -moz-outline: 1px dotted " + preferencesService.getCharPref(outlineColor) + " !important; }"));
  106.  
  107.                         // If the show outlined element names preference is set
  108.                         if(preferencesService.prefHasUserValue("webdeveloper.outline.show.element.names") && preferencesService.getBoolPref("webdeveloper.outline.show.element.names"))
  109.                         {
  110.                             styleElement.appendChild(pageDocument.createTextNode(outlineElementValue + ":before { content: \"<" + outlineElementValue + ">\" !important; }"));
  111.                         }
  112.                     }
  113.                 }
  114.             }
  115.  
  116.             // If there is a head element
  117.             if(headElementList.length > 0)
  118.             {
  119.                 headElementList[0].appendChild(styleElement);
  120.             }
  121.             else
  122.             {
  123.                 pageDocument.documentElement.appendChild(styleElement);
  124.             }
  125.         }
  126.  
  127.         // If applying styles
  128.         if(applyStyle)
  129.         {
  130.             webdeveloper_addAppliedStyle("webdeveloper-outline-custom-elements");
  131.         }
  132.     }
  133.     else
  134.     {
  135.         webdeveloper_removeStyleSheet("webdeveloper-outline-custom-elements", true);
  136.     }
  137.  
  138.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/imports/before.css", "webdeveloper-outline-custom-elements-before", applyStyle);
  139.     webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-outline-custom-elements-before-tooltips", "*:before");
  140. }
  141.  
  142. // Outlines all frames
  143. function webdeveloper_outlineFrames(element, applyStyle)
  144. {
  145.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_frames.css", "webdeveloper-outline-frames", applyStyle);
  146. }
  147.  
  148. // Outlines all the links without title attributes
  149. function webdeveloper_outlineLinksWithoutTitleAttributes(element, applyStyle)
  150. {
  151.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_links_without_title_attributes.css", "webdeveloper-outline-links-without-title-attributes", applyStyle);
  152. }
  153.  
  154. // Outlines the selected element
  155. function webdeveloper_outlineSelectedElement(element, applyStyle)
  156. {
  157.     const content      = window.document.getElementById("content");
  158.     const mainTabBox   = content.mTabBox;
  159.     const documentList = webdeveloper_getDocuments(content.browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  160.  
  161.     var checked      = element.getAttribute("checked");
  162.     var pageDocument = null;
  163.  
  164.     // Loop through the documents
  165.     for(var i = 0; i < documentList.length; i++)
  166.     {
  167.         pageDocument = documentList[i];
  168.  
  169.         // If outlining the selected element
  170.         if(checked)
  171.         {
  172.             pageDocument.addEventListener("mouseover", webdeveloper_displayElementAncestors, true);
  173.             pageDocument.addEventListener("click", webdeveloper_ignoreClick, true);
  174.         }
  175.         else
  176.         {
  177.             pageDocument.removeEventListener("mouseover", webdeveloper_displayElementAncestors, true);
  178.             pageDocument.removeEventListener("click", webdeveloper_ignoreClick, true);
  179.             window.content.status = null;
  180.         }
  181.     }
  182.  
  183.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_selected_element.css", "webdeveloper-outline-selected-element", applyStyle);
  184. }
  185.  
  186. // Outlines all table cells
  187. function webdeveloper_outlineTableCells(element, applyStyle)
  188. {
  189.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_table_cells.css", "webdeveloper-outline-table-cells", applyStyle);
  190. }
  191.  
  192. // Outlines all tables
  193. function webdeveloper_outlineTables(element, applyStyle)
  194. {
  195.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/outline_tables.css", "webdeveloper-outline-tables", applyStyle);
  196. }
  197.